--[[

k_smallblocks is a Minetest mod that adds smaller blocks to minetest aswell as 
its own node placement prediction/system

Copyright (C) 2019 Kurtzmusch

This file is part of k_smallblocks

k_smallblocks is free software; you can redistribute it and/or modify it under 
the terms of the GNU Lesser General Public License as published by the Free 
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

k_smallblocks is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with k_smallblocks. If not, see <https://www.gnu.org/licenses/>.

--]]


origin_bitmaps = { [255] = nil }
smallblocks.origin_bitmaps = origin_bitmaps

function check_shapes( bitmap )
	
	for i = 0, 255, 1 do
		if( origin_bitmaps[i] ~= nil ) then
			if(	util.bitmap_to_integer( bitmap ) == origin_bitmaps[i] ) then
				return true
			end
		end
	end
return false

end

function check_all_rotations( bitmap_as_int )
	local bitmap = util.integer_to_bitmap( bitmap_as_int )
	local rotated_bitmap = bitmap
	
	-- rotations around +y
	for i = 1, 4, 1 do
		rotated_bitmap = util.rotate_bitmap_around_plus_y( rotated_bitmap )
		if( check_shapes( rotated_bitmap ) ) then return true end
	end

	rotated_bitmap = util.orient_bitmap_towards_plus_z( bitmap )	
	for i = 1, 4, 1 do
		rotated_bitmap = util.rotate_bitmap_around_plus_z( rotated_bitmap )
		if( check_shapes( rotated_bitmap ) ) then return true end
	end

	rotated_bitmap = util.orient_bitmap_towards_minus_z( bitmap )
	for i = 1, 4, 1 do
		rotated_bitmap = util.rotate_bitmap_around_minus_z( rotated_bitmap )
		if( check_shapes( rotated_bitmap ) ) then return true end
	end

	rotated_bitmap = util.orient_bitmap_towards_plus_x( bitmap )
	for i = 1, 4, 1 do
		rotated_bitmap = util.rotate_bitmap_around_plus_x( rotated_bitmap )
		if( check_shapes( rotated_bitmap ) ) then return true end
	end

	rotated_bitmap = util.orient_bitmap_towards_minus_x( bitmap )
	for i = 1, 4, 1 do
		rotated_bitmap = util.rotate_bitmap_around_minus_x( rotated_bitmap )
		if( check_shapes( rotated_bitmap ) ) then return true end
	end

	rotated_bitmap = util.orient_bitmap_towards_minus_y( bitmap )
	for i = 1, 4, 1 do
		rotated_bitmap = util.rotate_bitmap_around_minus_y( rotated_bitmap )
		if( check_shapes( rotated_bitmap ) ) then return true end
	end

	return false
end

local index = 1
for bitmap_as_int = 1, 255, 1 do
	shape_exists = check_all_rotations( bitmap_as_int )	
	
	if( shape_exists == false ) then
		origin_bitmaps[index] = bitmap_as_int
		index = index + 1
		minetest.log( "none", " found shape "..bitmap_as_int )
	end

end

